// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#pragma once
#ifndef _RENDER_PROCESS_APP_H_
#define _RENDER_PROCESS_APP_H_

#include "include/cef_app.h"
#include "js_bridge/js_bridge.h"

class RenderProcessApp : public CefApp, public CefRenderProcessHandler {
public:
	RenderProcessApp() {};

	// CefApp methods:
	virtual CefRefPtr<CefRenderProcessHandler> GetRenderProcessHandler() override { return this; }

	// CefRenderProcessHandler methods.
	//virtual void OnRenderThreadCreated(CefRefPtr<CefListValue> extra_info) override;
	virtual void OnWebKitInitialized() override;
	virtual void OnBrowserCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefDictionaryValue> extra_info) override;
	virtual void OnBrowserDestroyed(CefRefPtr<CefBrowser> browser) override;
	virtual CefRefPtr<CefLoadHandler> GetLoadHandler() override;
	virtual void OnContextCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context) override;
	virtual void OnContextReleased(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context) override;
	virtual void OnUncaughtException(
		CefRefPtr<CefBrowser> browser,
		CefRefPtr<CefFrame> frame,
		CefRefPtr<CefV8Context> context,
		CefRefPtr<CefV8Exception> exception,
		CefRefPtr<CefV8StackTrace> stackTrace) override;
	virtual void OnFocusedNodeChanged(
		CefRefPtr<CefBrowser> browser,
		CefRefPtr<CefFrame> frame,
		CefRefPtr<CefDOMNode> node) override;
	virtual bool OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
		CefRefPtr<CefFrame> frame,
		CefProcessId source_process,
		CefRefPtr<CefProcessMessage> message) override;

private:
	// Include the default reference counting implementation.
	IMPLEMENT_REFCOUNTING(RenderProcessApp);

private:
	std::shared_ptr<JSBridge>	render_js_bridge_;
	bool						last_node_is_editable_{ false };
};

#endif  // _RENDER_PROCESS_APP_H_
